<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@page import="com.ubst.smartad.common.*" %>
<%@page import="com.ubst.smartad.env.*" %>
<%@page import="com.ubst.smartad.session.*" %>
<%@page import="com.ubst.smartad.logger.Debug" %>
<%@page import="net.sf.json.JSONArray"  %>
<%@page import="net.sf.json.JSONObject"  %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.ArrayList" %>
<%@page import="java.util.List" %>
<%@page import="java.io.PrintWriter" %>
<%@page import="com.ubst.smartad.dbpool.TransactionManager" %>
<%@page import="com.ubst.smartad.impl.admin.policy.PolicyMngImpl" %>
<%@include file="/jsp/inc/base.jsp"%>

<jsp:useBean id="tem" class="com.ubst.smartad.template.Template" scope="page"/>
<% 
// tem.setFileText( web_root+"skin1/test/test.html");
// tem.setReplaceKey("{TEST}", "aabbcc");

try{
	System.out.println("request.getParameterMap() "+request.getParameterMap());
	System.out.println("sord "+request.getParameter("sord"));
	System.out.println("page "+request.getParameter("page"));
	System.out.println("nd "+request.getParameter("nd"));
	System.out.println("sidx "+request.getParameter("sidx"));
	System.out.println("search "+request.getParameter("search"));
	System.out.println("rows "+request.getParameter("rows"));
	System.out.println("pagePlug "+request.getParameter("pagePlug"));
	
	//search: selectbox에 있는 search 조건값들
	System.out.println("sel_pw "+request.getParameter("sel_pw"));
	System.out.println("txt_1 "+request.getParameter("txt_1"));
	System.out.println("txt_2 "+request.getParameter("txt_2"));
	System.out.println("txt_3 "+request.getParameter("txt_3"));
	System.out.println("sel_array "+request.getParameter("sel_array"));
	System.out.println("sel_log "+request.getParameter("sel_log"));
	// orderBy와 searchStr에 해당값 세팅
	String orderBy = request.getParameter("sidx")+" "+request.getParameter("sord");//sort할 필드명,	sort 오름차내림차 
	String searchStr = request.getParameter("search");								//	search할 str
	
	/*
	*	setting
	*
	*//////////////////
	int curPage = Integer.parseInt(request.getParameter("page"));					//	현재 page
	
	if(request.getParameter("pagePlug") != null) {									// paging Plug 페이지
		curPage = Integer.parseInt(request.getParameter("pagePlug"));
	}
	
	int rows = Integer.parseInt(request.getParameter("rows"));						//	한페이지당 rows 수
	int prev_page = (curPage-1) * rows;	//limit first value
	int next_page = rows;				//limit second value
	///////////////////

	PolicyMngImpl policyMng = null;
	TransactionManager tm = new TransactionManager();
	
	policyMng = new PolicyMngImpl(tm.connection, serverName, fhostEnv.getLogLevel());
	List list = policyMng.getJqgridBasicList(searchStr, orderBy, prev_page, next_page);// list 가져오기

	int resRecords = list.size();	// 총 list 갯수
	int resTotal = resRecords / rows;// 총 페이지 갯수
	if ((resRecords % rows) > 0) { // 나머지가 있으면 +1
		resTotal++;
	}
	System.out.println("list "+list);
	JSONArray jsonArr = JSONArray.fromObject(list);
	JSONObject jsonObj = new JSONObject();
	jsonObj.put("rows", jsonArr);		// Data
	jsonObj.put("page", curPage);		// 현재 페이지
	jsonObj.put("records", resRecords);	// 총 List갯수	
	jsonObj.put("total", resTotal);		// 총 페이징 갯수
	
	response.setContentType("text/plain; charset=utf-8"); 
	response.setHeader("Cache-Control", "no-cache"); 
	//PrintWriter out = response.getWriter();
	out.print(jsonObj.toString());
	System.out.println("jsonObj.toString() "+jsonObj.toString());
	out.flush();
}catch (Exception e) {			
}

%>
				